home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ML_BME1.ZIP / PLASMA / MLPLASM.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1996-12-21  |  3.4 KB  |  141 lines

  1. {$M 8192,0,0}
  2. {$G+}
  3. uses files, alloc;
  4. {
  5.   Plasma v1.0
  6.   by Maple Leaf, 1996
  7.   ------------------------
  8.   The EXE file requires the external file PLASMA.DAT
  9. }
  10. var
  11.   plasma   : pointer;
  12.   movement : pointer;
  13.   colour   : pointer;
  14.   count    : word;
  15.  
  16. Procedure BRead(var f:file; var dest; count:longint);
  17. var bcopy,r:word;copied:longint;
  18. begin {$i-}
  19.   copied:=0;
  20.   repeat
  21.     if count>64000 then bcopy:=64000 else bcopy:=word(count);
  22.     blockread(f,ptr(seg(dest)+(copied div 16),ofs(dest)+(copied mod 16))^,bcopy,r);
  23.     copied:=copied+bcopy;
  24.     count:=count-bcopy;
  25.   until count<=0;
  26. end;
  27.  
  28. Procedure FreeMemory;
  29. begin
  30.   if not free(plasma) or
  31.      not free(movement) or
  32.      not free(colour) then writeln('Error deallocating memory. The system will probably crash.');
  33. end;
  34.  
  35. procedure LoadPlasm;
  36. var f:file; r:word;
  37. begin
  38.   plasma:=malloc(9600*16);
  39.   movement:=malloc(2500*16);
  40.   colour:=malloc(1920*16);
  41.   if (plasma=nil) or (movement=nil) or (colour=nil) then begin
  42.     writeln('Sorry, not enough memory.');
  43.     free(plasma); free(movement); free(colour);
  44.     halt;
  45.   end;
  46.   openforinput(f,'plasma.dat');
  47.   if ioresult<>0 then begin
  48.     writeln('Cannot load file PLASMA.DAT. Generate it first with GENP progs.');
  49.     FreeMemory;
  50.     halt
  51.   end;
  52.   BRead(f,plasma^,9600*16);          { Read plasma cloud }
  53.   BlockRead(f,movement^,40000,r);    { Read movement table }
  54.   BlockRead(f,colour^,30720,r);      { Read colour transition table }
  55.   closefile(f);
  56. end;
  57.  
  58. Procedure InitGraph;near;assembler;
  59. asm
  60.   mov ax,13h
  61.   int 10h
  62. end;
  63.  
  64. Procedure CloseGraph;near;assembler;
  65. asm
  66.   mov ax,3
  67.   int 10h
  68. end;
  69.  
  70. Procedure ShowPlasm;near;assembler;
  71. asm
  72.     mov count,0
  73.     mov ax,0a000h
  74.     mov es,ax
  75.     sub ax,ax
  76. @MainLoop:
  77.     mov dx,3DAh
  78.     in al,dx
  79.     test al,8
  80.     je @MainLoop  { Wait for vertical retrace }
  81.     mov bx,count
  82.     mov si,bx
  83.     shl si,1
  84.     add si,bx     { SI = count*3 }
  85.     { Set a palette ... }
  86.     mov dx,3c8h
  87.     mov al,1
  88.     out dx,al
  89.     inc dx
  90.     mov cx,0FFh
  91.     push ds
  92.     mov ds,word ptr colour[2]
  93.     cld
  94. @l3:outsb
  95.     outsb
  96.     outsb
  97.     loop @l3
  98.     pop ds { Restore DS register }
  99.     mov di,bx { BX is already = to COUNT }
  100.     shl di,2
  101.     push ds
  102.     mov ds,word ptr movement[2]
  103.     mov si,[di]     { point 1 }
  104.     mov bx,[di+2]   { point 2 }
  105.     pop ds
  106.     push ds
  107.     mov ds,word ptr plasma[2]   { Segment of plasma's start }
  108.     mov di,40                   { Starting offset }
  109.     mov ch,200                  { y loop = 200 pixels }
  110. @l1:mov cl,60                   { x loop = 60*4 = 240 pixels }
  111. @l2:db 66h; lodsw               { Load 4 bytes from source }
  112.     db 66h; add ax,[si+bx]      { Add 4 source pixels }
  113.     db 66h; stosw               { Put bytes as pixels }
  114.     dec cl
  115.     jnz @l2                     { Do the second loop }
  116.     add di,80
  117.     sub si,240                  { Reset source }
  118.     mov dx,ds
  119.     add dx,32
  120.     mov ds,dx                   { DS:=DS+32, this means 32*16=512 bytes down in source memory }
  121.     dec ch
  122.     jnz @l1                     { Do the first loop }
  123.     pop ds
  124.     inc count
  125.     cmp count,10000
  126.     jb @NoReset
  127.     mov count,0                 { Reset counter at the end of a cycle }
  128. @NoReset:
  129.     mov ah,0bh
  130.     int 21h
  131.     or al,al
  132.     jz @MainLoop                { repeat until keypressed ... }
  133. end;
  134.  
  135. begin
  136.   LoadPlasm;
  137.   InitGraph;
  138.   ShowPlasm;
  139.   CloseGraph;
  140.   FreeMemory;
  141. end.